package manager;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;

import controller.Connection;
import bean.ConnectionMessage;
import bean.Message;

public class ComManager {

	public Message sendMessage(Message m){
		try {
		Connection c  = new Connection();
		HttpURLConnection connect = c.getConnection();
		DataOutputStream dos;
		DataInputStream dis;
		dos = new DataOutputStream(connect.getOutputStream());
		XMLEncoder encoder = new XMLEncoder(dos);
		encoder.writeObject(m);
		encoder.flush();
		encoder.close();
		dis = new DataInputStream(connect.getInputStream());
		XMLDecoder decoder = new XMLDecoder(dis);
		//
		return (Message)decoder.readObject();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}
}
